﻿using LeHouse.Server.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeHouse.Server.Service
{
    public class transmitHelper
    {
        /// <summary>
        /// 根据报告号获取所有的相关信息
        /// </summary>
        /// <returns></returns>
        public static TrackRecords transmitHelperByReportNumber(string T_ReportNumber)
        {
            TrackRecords obj = new TrackRecords();
            Collateral_PersonalService personalservice = new Collateral_PersonalService();//创建抵押物权益状况表

            var d1 = personalservice.Select().Where(p => p.T_ReportNumber == T_ReportNumber).FirstOrDefault();
            if(d1==null)
            {
                return null;
            }
            obj.T_ReportNumber = T_ReportNumber;

            Collateral_BorrowerService borrowerservice = new Collateral_BorrowerService();//借款人信息表
            Collateral_ZoneService zoneservice=new Collateral_ZoneService();//创建抵押物区位状况表

            var d2 = borrowerservice.Select().Where(p => p.T_ReportNumber == T_ReportNumber).FirstOrDefault();
            var d3 = zoneservice.Select().Where(p => p.T_ReportNumber == T_ReportNumber).FirstOrDefault();
            var d4 = borrowerservice.Select().Where(p => p.T_ReportNumber == T_ReportNumber).FirstOrDefault();
            var d5 = borrowerservice.Select().Where(p => p.T_ReportNumber == T_ReportNumber).FirstOrDefault();

            obj.T_State = d1.T_State;
            obj.T_Linkman = d1.T_Linkman;
            obj.T_Phone = d1.T_Phone;
            obj.T_Located = d1.T_Located;
            obj.T_Date = d1.T_Date;
            obj.T_Loanyear = d1.T_Loanyear;
            
            if(d2!=null)
            {
                obj.T_Idcard = d2.T_Idcard;
            }


            return obj;
        }


        /// <summary>
        /// 将小写数字转化为大写汉子
        /// </summary>
        /// <param name="Digital"></param>
        /// <returns></returns>
        public static string chang(double Digital)
        {
            //将小写金额转换成大写金额           
            String[] MyScale = { "分", "角", "圆", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟" };
            String[] MyBase = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
            String moneyStr = "";
            bool isPoint = false;
            string moneyDigital = Digital.ToString();
            if (moneyDigital.IndexOf(".") != -1)
            {
                moneyDigital = moneyDigital.Remove(moneyDigital.IndexOf("."), 1);
                isPoint = true;
            }
            for (int i = moneyDigital.Length; i > 0; i--)
            {
                int MyData = Convert.ToInt16(moneyDigital[moneyDigital.Length - i].ToString());
                moneyStr += MyBase[MyData];
                if (isPoint == true)
                {
                    moneyStr += MyScale[i - 1];
                }
                else
                {
                    moneyStr += MyScale[i + 1];
                }
            }
            while (moneyStr.Contains("零零"))
                moneyStr = moneyStr.Replace("零零", "零");
            moneyStr = moneyStr.Replace("零亿", "亿");
            moneyStr = moneyStr.Replace("亿万", "亿");
            moneyStr = moneyStr.Replace("零万", "万");
            moneyStr = moneyStr.Replace("零仟", "零");
            moneyStr = moneyStr.Replace("零佰", "零");
            moneyStr = moneyStr.Replace("零拾", "零");
            while (moneyStr.Contains("零零"))
                moneyStr = moneyStr.Replace("零零", "零");
            moneyStr = moneyStr.Replace("零圆", "圆");
            moneyStr = moneyStr.Replace("零角", "");
            moneyStr = moneyStr.Replace("零分", "");
            moneyStr = moneyStr + "整";
            return moneyStr;
        }


    }
}
